home *** CD-ROM | disk | FTP | other *** search
- class Kid
- {
- var engine;
- var mc;
- var skin;
- var hair;
- var body;
- var feet;
- var maxStamina;
- var stamina;
- var distAlongPath;
- var following;
- var endOfPathHandler;
- var followPathUntil;
- var pump;
- var slotNum;
- var oldPumpPos;
- var n;
- var leaving = false;
- var _happy = true;
- var _knackered = false;
- static var KID_MC = "kid";
- static var MIN_STAMINA = 1000;
- static var MAX_STAMINA = 2000;
- static var TIRED_POINT = 0.5;
- static var EXHAUSTED_POINT = 0.25;
- static var MAX_SLOW = -0.5;
- static var RUN_TO_SLOT_SPEED = 0.015;
- function Kid(e)
- {
- super();
- this.engine = e;
- this.mc = this.engine.back.attachMovie(Kid.KID_MC,Kid.KID_MC + getTimer(),0,{kid:this,isDownHill:false,engine:this.engine});
- this.skin = Rand.random(1,this.mc.inner.head._totalframes,0);
- this.hair = Rand.random(1,this.mc.inner.hair._totalframes,0);
- this.body = Rand.random(1,this.mc.inner.body._totalframes,0);
- this.feet = Rand.random(1,this.mc.inner.leftFoot._totalframes,0);
- this.maxStamina = this.stamina = Rand.random(Kid.MIN_STAMINA,Kid.MAX_STAMINA,0);
- this.setAvatar();
- this.followPath(this.engine.enteringLabourPool1,this.swapMcToFront);
- }
- function setAvatar()
- {
- this.mc.inner.head.gotoAndStop(this.skin);
- this.mc.inner.hair.gotoAndStop(this.hair);
- this.mc.inner.body.gotoAndStop(this.body);
- this.mc.inner.leftHand.gotoAndStop(this.skin);
- this.mc.inner.rightHand.gotoAndStop(this.skin);
- this.mc.inner.leftFoot.gotoAndStop(this.feet);
- this.mc.inner.rightFoot.gotoAndStop(this.feet);
- var _loc2_ = 1 - this.stamina / this.maxStamina;
- this.mc.inner.head.red.gotoAndStop(Math.floor(_loc2_ * (this.mc.inner.head.red._totalframes - 1)) + 1);
- }
- function followPath(path, eop, until, startPoint)
- {
- this.distAlongPath = !isNaN(startPoint) ? startPoint : 1;
- this.following = path;
- this.endOfPathHandler = eop;
- this.followPathUntil = !isNaN(until) ? until : path.length;
- }
- function update(f)
- {
- if(this.following)
- {
- this.mc.setPos(this.following.getPositionAtFrame(++this.distAlongPath,this.mc._parent));
- if(this.distAlongPath >= this.followPathUntil)
- {
- this.reachedEndOfPath();
- }
- }
- else if(this.pump)
- {
- if(this.slotNum !== undefined)
- {
- var _loc4_ = this.pump.getPositionOfSlot(this.slotNum);
- var _loc2_ = undefined;
- var _loc3_ = undefined;
- if(_loc4_ > this.distAlongPath)
- {
- _loc2_ = _loc4_ - this.distAlongPath;
- if(_loc2_ > 0.5)
- {
- _loc2_ = 1 - _loc2_;
- _loc3_ = -1;
- }
- else
- {
- _loc3_ = 1;
- }
- }
- else
- {
- _loc2_ = this.distAlongPath - _loc4_;
- if(_loc2_ > 0.5)
- {
- _loc2_ = 1 - _loc2_;
- _loc3_ = 1;
- }
- else
- {
- _loc3_ = -1;
- }
- }
- if(_loc2_ <= Kid.RUN_TO_SLOT_SPEED)
- {
- this.reachedSlot();
- }
- else
- {
- if(_loc3_ > 0)
- {
- this.distAlongPath += Kid.RUN_TO_SLOT_SPEED;
- }
- else
- {
- this.distAlongPath -= Kid.RUN_TO_SLOT_SPEED;
- }
- this.distAlongPath = this.numberWrap(this.distAlongPath,1);
- var _loc5_ = Math.floor(this.distAlongPath * this.pump.goToSlotGuide.length) + 1;
- this.mc.setPos(this.pump.goToSlotGuide.getPositionAtFrame(_loc5_,this.mc._parent));
- }
- }
- else
- {
- this.stamina -= this.pump.effort;
- var _loc6_ = this.pump.getPositionOfSlot(this.pump.getSlotForKid(this));
- if(this.stamina < 0)
- {
- this.stamina = 0;
- }
- this.oldPumpPos = _loc6_;
- }
- }
- if(!this.leaving)
- {
- if(this.happy)
- {
- this.checkIfHappy();
- if(!this.happy)
- {
- this.mc.startSweating();
- this.engine.tiredTip();
- }
- }
- if(!this.happy)
- {
- if(!this.knackered)
- {
- this.checkIfKnackered();
- if(this.knackered)
- {
- this.mc.changeKnackered(true);
- this.engine.exhaustedTip();
- }
- }
- }
- }
- this.mc.update();
- this.mc.inner.head.setTiredness(1 - this.stamina / this.maxStamina);
- }
- function numberWrap(n, r)
- {
- n %= r;
- return n >= 0 ? n : r + n;
- }
- function joinPump(p, sn)
- {
- this.pump = p;
- this.slotNum = sn;
- this.distAlongPath = 0;
- }
- function reachedSlot()
- {
- this.oldPumpPos = this.pump.getPositionOfSlot(this.slotNum);
- this.mc.joinedPump();
- this.pump.slots[this.slotNum] = this;
- delete this.slotNum;
- }
- function leavePump()
- {
- var _loc2_ = this.pump.getPositionOfSlot(this.pump.getSlotForKid(this));
- this.pump.leave(this);
- var _loc3_ = undefined;
- if(_loc2_ > PlayPump.KID_LEAVE_POINT)
- {
- _loc3_ = this.pump.leaveRight;
- _loc2_ = 1 - _loc2_;
- }
- else
- {
- _loc3_ = this.pump.leaveLeft;
- }
- _loc2_ *= 2;
- this.followPath(_loc3_,this.joinPumpExit,_loc3_.length,Math.floor(_loc3_.length * _loc2_) + 1);
- this.mc.leftPump();
- this.mc.stopSweating();
- this._knackered = false;
- this.mc.changeKnackered(false);
- this.leaving = true;
- }
- function joinPumpExit()
- {
- this.followPath(this.pump.exit,Delegate.create(this,this.followPath,this.engine.leavingGame1,Delegate.create(this,this.swapMcToBack)));
- delete this.pump;
- }
- function reachedEndOfPath()
- {
- delete this.following;
- delete this.followPathUntil;
- var _loc2_ = this.endOfPathHandler;
- delete this.endOfPathHandler;
- _loc2_.call(this);
- }
- function goTo(queue)
- {
- this.followPath(queue.path,Delegate.create(this,this.isKidAtEndOfQueue,queue),1);
- queue.joinedQueue(this);
- }
- function joinedQueue(queue)
- {
- this.isKidAtEndOfQueue(queue);
- }
- function sendToNewPath(newPath, followedPath)
- {
- if(this.following === undefined)
- {
- this.followPath(newPath,followedPath);
- }
- else
- {
- this.followPath(this.following,Delegate.create(this,this.followPath,newPath,followedPath),null,this.distAlongPath);
- }
- }
- function sendToNewQueue(newQueue, fromQueue)
- {
- if(this.following === undefined)
- {
- this.goTo(newQueue);
- }
- else
- {
- this.followPath(this.following,Delegate.create(this,this.goTo,newQueue),null,this.distAlongPath);
- }
- fromQueue.kidLeaveQueue();
- }
- function isKidAtEndOfQueue(queue)
- {
- var _loc2_ = 0;
- while(_loc2_ < queue.length)
- {
- if(queue[_loc2_] == this)
- {
- var _loc4_ = queue.path.length - Queue.QUEUE_SEPARATION * _loc2_;
- }
- _loc2_ = _loc2_ + 1;
- }
- if(this.distAlongPath != _loc4_)
- {
- this.followPath(queue.path,Delegate.create(this,this.isKidAtEndOfQueue,queue),this.distAlongPath + 1,this.distAlongPath);
- }
- else
- {
- this.mc.setPose(KidMc.IDLE);
- }
- }
- function swapMcToFront()
- {
- var _loc2_ = this.mc._name;
- var _loc3_ = this.mc.getTargetDepth();
- this.mc.die();
- this.mc = this.engine.pumpsHolder.attachMovie(Kid.KID_MC,_loc2_,_loc3_,{kid:this,isDownHill:true,engine:this.engine,xdir:-1});
- this.setAvatar();
- this.mc.setPos(this.engine.enteringLabourPool1.getPositionAtFrame(this.engine.enteringLabourPool1.length - 1,this.mc._parent));
- this.goTo(this.engine.labourPool);
- this.update();
- }
- function swapMcToBack()
- {
- var _loc2_ = this.mc._name;
- var _loc3_ = this.mc.getTargetDepth();
- this.mc.die();
- this.mc = this.engine.back.attachMovie(Kid.KID_MC,_loc2_,_loc3_,{kid:this,isDownHill:false,engine:this.engine});
- this.setAvatar();
- this.followPath(this.engine.leavingGame2,Delegate.create(this,this.die));
- this.update();
- }
- function checkIfHappy()
- {
- if(this.stamina / this.maxStamina < Kid.TIRED_POINT)
- {
- this._happy = false;
- }
- else
- {
- this._happy = true;
- }
- }
- function checkIfKnackered()
- {
- if(this.stamina / this.maxStamina < Kid.EXHAUSTED_POINT)
- {
- this._knackered = true;
- }
- else
- {
- this._knackered = false;
- }
- }
- function die()
- {
- if(this.mc)
- {
- this.mc.die();
- }
- var _loc2_ = 0;
- while(_loc2_ < this.engine.allKids.length)
- {
- if(this.engine.allKids[_loc2_] == this)
- {
- this.engine.allKids.splice(_loc2_,1);
- break;
- }
- _loc2_ = _loc2_ + 1;
- }
- this.engine.indQueue.push(this.n);
- }
- function get happy()
- {
- return this._happy;
- }
- function get knackered()
- {
- return this._knackered;
- }
- function get pushForce()
- {
- var _loc2_ = this.stamina / this.maxStamina;
- if(_loc2_ >= Kid.TIRED_POINT)
- {
- return 1;
- }
- if(_loc2_ < Kid.EXHAUSTED_POINT)
- {
- return (Kid.EXHAUSTED_POINT - _loc2_) / Kid.EXHAUSTED_POINT * Kid.MAX_SLOW;
- }
- _loc2_ -= Kid.EXHAUSTED_POINT;
- return _loc2_ / (Kid.TIRED_POINT - Kid.EXHAUSTED_POINT);
- }
- function toString()
- {
- return "kid " + this.n;
- }
- }
-